
package com.scalar.chiptrack.jobs;

import java.util.Date;
/* Mallikarjun Ankati edited on 11/15/2004
 *  1) Changed Frequency in hours and minutes.
 *  2) Added minutes Frequency.
 *  3) Added new contructor in order to support legacy application
 *
 *
 */
public class Job {

    public static final String STATUS_NEW       = "New";
    public static final String STATUS_SCHEDULED = "Scheduled";
    public static final String STATUS_RUNNING   = "Running";
    public static final String STATUS_DONE      = "Completed";
    public static final String STATUS_FAILED    = "Failed";
    public static final String STATUS_ABORTED   = "Aborted";

    private int m_id = -1;
    private int m_statusId = -1;
    private String m_name = null;
    private String m_handler = null;
    private Date m_startTime = null;
    private Date m_endTime = null;
    private long m_timeTaken = 0;

    private long m_frequencyInHours = 0;
    private long m_frequencyInMinutes = 0;

    private String m_status = STATUS_NEW;
    private boolean m_isSystem= false;
    private boolean m_isDisabled = false; // Stores the Value of Removed flag.
    private String m_startDate;
    private String m_endDate;
    protected String[] m_selectedWeekDays = { };
    private String m_scheduleTime = null;
    private String m_scheduleMinute = null;
    private int m_am_pm = 0;
    private String m_repeatTask;
    private String m_occurs;
    private String m_everyDaily;
    private String m_everyWeekly;
    private String m_everyMonthly;
    private String m_everyDay;
    private String m_emails;
    private String[] emailUserId;
    private String ftpUrl           = null;
    private String directory        = null;
    private String userName         = null;
    private String password         = null;
    private String connectionMode   = null;

    public Job() {
    }

    public Job (int id, String name, String handler, Date startTime) {
        m_id = id;
        m_name = name;
        m_handler = handler;
        m_startTime = startTime;
    }

    public Job (int id, String name, String handler, Date startTime, long freqInHours, long freqInMinutes, boolean isDisabled) {
        m_id = id;
        m_name = name;
        m_handler = handler;
        m_startTime = startTime;
        m_frequencyInHours = freqInHours;
        m_frequencyInMinutes = freqInMinutes;
        m_isDisabled = isDisabled;
    }

    public Job (int id, String name, String handler, Date startTime, long freq)
    {
        m_id = id;
        m_name = name;
        m_handler = handler;
        m_startTime = startTime;
        m_frequencyInHours = freq;
    }

	public Job (int id, String name, String handler, Date startTime, long freqInHours, long freqInMinutes)
    {
        m_id = id;
        m_name = name;
        m_handler = handler;
        m_startTime = startTime;
        m_frequencyInHours = freqInHours;
        m_frequencyInMinutes = freqInMinutes;
    }

    public Job (int id, int statusId, String name, Date startTime, Date endTime, long timeTaken, String status)
    {
        m_id = id;
        m_statusId = statusId;
        m_name = name;
        m_startTime = startTime;
        m_endTime = endTime;
        m_timeTaken = timeTaken;
        m_status = status;
    }
    public Job (int id, String name, String handler, Date startTime, long freqInHours, long freqInMinutes, boolean isDisabled, String scheduleTime, String scheduleMinute, int amPm ) {
        m_id = id;
        m_name = name;
        m_handler = handler;
        m_startTime = startTime;
        m_frequencyInHours = freqInHours;
        m_frequencyInMinutes = freqInMinutes;
        m_isDisabled = isDisabled;
        m_scheduleTime= scheduleTime;
        m_scheduleMinute = scheduleMinute;
        m_am_pm= amPm;
    }



    public int getId() {
        return m_id;
    }
    public void setId (int id) {
        m_id = id;
    }

    public int getStatusId() {
        return m_statusId;
    }
    public void setStatusId (int id) {
        m_statusId = id;
    }

    public String getName() {
        return m_name;
    }
    public void setName (String name) {
        m_name = name;
    }

    public String getJobName() {
        return m_name;
    }

    public void setJobName (String jobName) {
        m_name = jobName;
    }

    public boolean getDisabled() {
        return m_isDisabled;
    }

    public void setDisabled (boolean disabled) {
        m_isDisabled = disabled;
    }
    public String getHandler() {
        return m_handler;
    }
    public JobHandler getHandlerObject() throws Exception {
        //System.out.println ("handler = " + m_handler);
        JobHandler handler = (JobHandler) Class.forName(m_handler).newInstance();
        handler.setJob (this);
        return handler;
    }
    public void setHandler (String handler) {
        m_handler = handler;
    }

    public Date getStartTime() {
        return m_startTime;
    }
    public void setStartTime (Date startTime) {
        m_startTime = startTime;
    }

    public Date getEndTime() {
        return m_endTime;
    }
    public void setEndTime (Date endTime) {
        m_endTime = endTime;
    }

    public long getTimeTaken() {
        return m_timeTaken;
    }
    public void setTimeTaken (long timeTaken) {
        m_timeTaken = timeTaken;
    }

    public long getFrequencyInHours() {
        return m_frequencyInHours;
    }
    public void setFrequencyInHours (long frequency) {
        m_frequencyInHours = frequency;
    }

	public long getFrequencyInMinutes() {
        return m_frequencyInMinutes;
    }

    public void setFrequencyInMinutes(long frequency){
    	m_frequencyInMinutes = frequency;
    }

    public String getStatus() {
        return m_status;
    }

    public void setStatus (String status) {
        m_status = status;
    }

    public boolean isSystem()
    {
        return m_isSystem;
    }
    public void setIsSystem(boolean isSystem)
    {
        m_isSystem = isSystem;
    }

    public void setStartDate(String startDate)
    {
        this.m_startDate = startDate;
    }

    public String getStartDate(){
        return m_startDate;
    }

    public void setEndDate(String endDate )
    {
        this.m_endDate = endDate;
    }

    public String getEndDate(){
        return m_endDate;
    }

    public String[] getSelectedWeekDays()
    {
       return m_selectedWeekDays;
    }
    public void setSelectedWeekDays(String[] selectedWeekDays)
    {
        this.m_selectedWeekDays = selectedWeekDays;
    }
    public void setScheduleTime(String scheduleTime)
    {
        this.m_scheduleTime = scheduleTime;
    }

    public String getScheduleTime(){
        return m_scheduleTime;
    }

    public String getScheduleMinute()
    {
        if ( m_scheduleMinute != null && m_scheduleMinute.length() == 1 )
        {
            m_scheduleMinute  = "0" + m_scheduleMinute;
        }
        return m_scheduleMinute;
    }

    public void setScheduleMinute(String scheduleMinute)
    {
        this.m_scheduleMinute = scheduleMinute;
    }

    public void setAmPm(int am_pm)
    {
        this.m_am_pm = am_pm;
    }

    public int getAmPm(){
        return m_am_pm;
    }

    public void setRepeatTask(String repeatTask )
    {
        this.m_repeatTask = repeatTask;
    }

    public String getRepeatTask(){
        return m_repeatTask;
    }

    public void setOccurs(String occurs )
    {
        this.m_occurs = occurs;
    }

    public String getOccurs(){
        return m_occurs;
    }

    public void setEveryDaily(String daily )
    {
        this.m_everyDaily = daily;
    }

    public String getEveryDaily(){
        return m_everyDaily;
    }

    public void setEveryWeekly(String weekly )
    {
        this.m_everyWeekly = weekly;
    }

    public String getEveryWeekly(){
        return m_everyWeekly;
    }

    public void setEveryMonthly(String monthly )
    {
        this.m_everyMonthly = monthly;
    }

    public String getEveryMonthly(){
        return m_everyMonthly;
    }

    public void setEveryDay(String day )
    {
        this.m_everyDay = day;
    }

    public String getEveryDay(){
        return m_everyDay;
    }

    public void setEmails(String emails )
    {
        this.m_emails = emails;
    }

    public String getEmails(){
        return m_emails;
    }

    public String[] getEmailUserId() {
        return emailUserId;
    }

    public void setEmailUserId(String[] emailUserId) {
        this.emailUserId = emailUserId;
    }

    public String getFtpUrl() {
        return ftpUrl;
    }

    public void setFtpUrl(String ftpUrl) {
        this.ftpUrl = ftpUrl;
    }

    public String getDirectory() {
        return directory;
    }

    public void setDirectory(String directory) {
        this.directory = directory;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getConnectionMode() {
        return connectionMode;
    }

    public void setConnectionMode(String connectionMode) {
        this.connectionMode = connectionMode;
    }

    public String toString() {
        return "name = "      + m_name      + "\n" +
               "handler = "   + m_handler   + "\n" +
               "startTime = " + m_startTime + "\n" +
               "timeTaken = " + m_timeTaken + "\n" +
               "frequency = Every " + m_frequencyInHours + "hrs "+m_frequencyInMinutes+"min \n" +
               "status = " + m_status;
    }
}